home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cocktail
/
cg.lha
/
cg
/
src
/
GramC.mi
< prev
next >
Wrap
Text File
|
1992-11-24
|
24KB
|
1,136 lines
IMPLEMENTATION MODULE GramC;
IMPORT SYSTEM, System, IO, Tree;
(* line 5 "" *)
FROM IO IMPORT WriteS, WriteNl;
FROM Strings IMPORT tString, ArrayToString;
FROM StringMem IMPORT WriteString;
FROM Idents IMPORT NoIdent, tIdent, MakeIdent;
FROM Texts IMPORT WriteText;
FROM Sets IMPORT IsElement, Include;
FROM TreeC2 IMPORT TreeIO;
FROM Tree IMPORT
NoTree , tTree , Input , Reverse ,
Class , NoClass , Child , Attribute ,
ActionPart , HasSelector , HasAttributes , NoCodeAttr ,
Referenced , Options , TreeRoot , QueryTree ,
ClassCount , iNoTree , itTree , Generated ,
f , WI, WE, WN , ForallClasses , ForallAttributes,
Nonterminal , Terminal , IdentifyAttribute,
String , iPosition ;
IMPORT Strings;
VAR
Node, ActClass, TheClass, TheAttr : tTree;
iOper, iLeft, iRight, iNone, iPrec, iRule : tIdent;
ActActionIndex, PrevActionIndex : SHORTCARD;
IsImplicit : BOOLEAN;
s : tString;
PROCEDURE GetBaseClass (Class: tTree): tTree;
BEGIN
WHILE Class^.Class.BaseClass^.Kind # NoClass DO
Class := Class^.Class.BaseClass;
END;
RETURN Class;
END GetBaseClass;
PROCEDURE IsLast (Class, Action: tTree): BOOLEAN;
VAR Found, Last: BOOLEAN;
BEGIN
IsLast2 (Class, Action, Found, Last);
RETURN Last;
END IsLast;
PROCEDURE IsLast2 (t, Action: tTree; VAR pFound, pLast: BOOLEAN);
VAR Found, Last: BOOLEAN;
BEGIN
CASE t^.Kind OF
| Class:
IsLast2 (t^.Class.Attributes, Action, pFound, pLast);
IF pFound OR NOT pLast THEN RETURN; END;
IsLast2 (t^.Class.BaseClass, Action, pFound, pLast);
| Child:
IsLast2 (t^.Child.Next, Action, Found, Last);
pFound := Found;
IF Found THEN
pLast := Last;
ELSE
pLast := FALSE;
END;
| Attribute:
IsLast2 (t^.Attribute.Next, Action, pFound, pLast);
| ActionPart:
IsLast2 (t^.ActionPart.Next, Action, Found, Last);
pFound := Found OR (Action = t);
IF Found THEN
pLast := Last;
ELSE
pLast := Last AND (Action = t);
END;
ELSE
pFound := FALSE;
pLast := TRUE;
END;
END IsLast2;
PROCEDURE Prefix;
BEGIN
IF TreeRoot^.Ag.ScannerName # NoIdent THEN WI (TreeRoot^.Ag.ScannerName); WriteS (f, "_"); END;
END Prefix;
PROCEDURE yyAbort (yyFunction: ARRAY OF CHAR);
BEGIN
IO.WriteS (IO.StdError, 'Error: module GramC, routine ');
IO.WriteS (IO.StdError, yyFunction);
IO.WriteS (IO.StdError, ' failed');
IO.WriteNl (IO.StdError);
Exit;
END yyAbort;
PROCEDURE yyIsEqual (yya, yyb: ARRAY OF SYSTEM.BYTE): BOOLEAN;
VAR yyi : INTEGER;
BEGIN
FOR yyi := 0 TO INTEGER (HIGH (yya)) DO
IF yya [yyi] # yyb [yyi] THEN RETURN FALSE; END;
END;
RETURN TRUE;
END yyIsEqual;
PROCEDURE ParsSpec (t: Tree.tTree);
VAR yyTempo: RECORD CASE : INTEGER OF
END; END;
BEGIN
IF t = Tree.NoTree THEN RETURN; END;
IF (t^.Kind = Tree.Ag) THEN
(* line 98 "" *)
WITH t^.Ag DO
(* line 98 "" *)
IF ScannerName # NoIdent THEN
WriteS (f, "SCANNER "); WI (ScannerName);
END;
WriteS (f, " PARSER "); WI (ParserName); WriteNl (f);
WriteS (f, "GLOBAL {"); WriteNl (f);
WriteText (f, ParserCodes^.Codes.Global);
Node := Modules;
WHILE Node^.Kind = Tree.Module DO
WriteText (f, Node^.Module.ParserCodes^.Codes.Global);
Node := Node^.Module.Next;
END;
ParsVariant (Classes);
WriteNl (f);
WriteS (f, "typedef union {"); WriteNl (f);
WriteS (f, " "); Prefix; WriteS (f, "tScanAttribute Scan;"); WriteNl (f);
Node := Classes;
WHILE Node^.Kind = Class DO
WITH Node^.Class DO
IF {Nonterminal, Referenced, HasAttributes} <= Properties THEN
IF (String IN Properties) AND NOT (HasSelector IN Properties) THEN
WriteS (f, " yy"); WN (Name); WriteS (f, " /* "); WE (Name); WriteS (f, " */ yy"); WN (Name); WriteS (f, ";"); WriteNl (f);
ELSE
WriteS (f, " yy"); WI (Selector); WriteS (f, " "); WI (Selector); WriteS (f, ";"); WriteNl (f);
END;
END;
Node := Next;
END;
END;
WriteS (f, "} tParsAttribute;"); WriteNl (f);
WriteS (f, "}"); WriteNl (f);
WriteNl (f);
WriteS (f, "EXPORT {"); WriteNl (f);
WriteText (f, ParserCodes^.Codes.Export);
Node := Modules;
WHILE Node^.Kind = Tree.Module DO
WriteText (f, Node^.Module.ParserCodes^.Codes.Export);
Node := Node^.Module.Next;
END;
WriteS (f, "}"); WriteNl (f);
WriteNl (f);
WriteS (f, "LOCAL {"); WriteNl (f);
WriteText (f, ParserCodes^.Codes.Local);
Node := Modules;
WHILE Node^.Kind = Tree.Module DO
WriteText (f, Node^.Module.ParserCodes^.Codes.Local);
Node := Node^.Module.Next;
END;
WriteS (f, "}"); WriteNl (f);
WriteNl (f);
WriteS (f, "BEGIN {"); WriteNl (f);
WriteText (f, ParserCodes^.Codes.Begin);
Node := Modules;
WHILE Node^.Kind = Tree.Module DO
WriteText (f, Node^.Module.ParserCodes^.Codes.Begin);
Node := Node^.Module.Next;
END;
WriteS (f, "}"); WriteNl (f);
WriteNl (f);
WriteS (f, "CLOSE {"); WriteNl (f);
WriteText (f, ParserCodes^.Codes.Close);
Node := Modules;
WHILE Node^.Kind = Tree.Module DO
WriteText (f, Node^.Module.ParserCodes^.Codes.Close);
Node := Node^.Module.Next;
END;
WriteS (f, "}"); WriteNl (f);
WriteNl (f);
WriteS (f, "TOKEN"); WriteNl (f);
WriteNl (f);
ForallClasses (Classes, Token);
WriteNl (f);
WriteS (f, "OPER"); WriteNl (f);
WriteNl (f);
PrecDefs (Precs);
WriteNl (f);
WriteS (f, "RULE"); WriteNl (f);
WriteNl (f);
ForallClasses (Classes, ParsSpec);
;
RETURN;
END;
END;
IF (t^.Kind = Tree.Class) THEN
(* line 178 "" *)
WITH t^.Class DO
(* line 178 "" *)
IF {Nonterminal, Referenced} <= Properties THEN
TheClass := t;
Grammar (t);
END;
;
RETURN;
END;
END;
END ParsSpec;
PROCEDURE ScanSpec (t: Tree.tTree);
VAR yyTempo: RECORD CASE : INTEGER OF
END; END;
BEGIN
IF t = Tree.NoTree THEN RETURN; END;
IF (t^.Kind = Tree.Ag) THEN
(* line 188 "" *)
WITH t^.Ag DO
(* line 188 "" *)
WriteS (f, "c"); WriteNl (f);
WriteS (f, "# if defined __STDC__ | defined __cplusplus"); WriteNl (f);
WriteS (f, "# define ARGS(parameters) parameters"); WriteNl (f);
WriteS (f, "# else"); WriteNl (f);
WriteS (f, "# define ARGS(parameters) ()"); WriteNl (f);
WriteS (f, "# endif"); WriteNl (f);
WriteNl (f);
ForallClasses (Classes, ScanVariant);
WriteNl (f);
WriteS (f, "typedef union {"); WriteNl (f);
WriteS (f, " tPosition Position;"); WriteNl (f);
ForallClasses (Classes, ScanAttr);
WriteS (f, "} "); Prefix; WriteS (f, "tScanAttribute;"); WriteNl (f);
WriteNl (f);
WriteS (f, "extern void "); Prefix; WriteS (f, "ErrorAttribute ARGS((int Token, "); Prefix; WriteS (f, "tScanAttribute * pAttribute));"); WriteNl (f);
WriteS (f, "%%"); WriteNl (f);
WriteS (f, "void "); Prefix; WriteS (f, "ErrorAttribute"); WriteNl (f);
WriteS (f, "# if defined __STDC__ | defined __cplusplus"); WriteNl (f);
WriteS (f, " (int Token, "); Prefix; WriteS (f, "tScanAttribute * pAttribute)"); WriteNl (f);
WriteS (f, "# else"); WriteNl (f);
WriteS (f, " (Token, pAttribute) int Token; "); Prefix; WriteS (f, "tScanAttribute * pAttribute;"); WriteNl (f);
WriteS (f, "# endif"); WriteNl (f);
WriteS (f, "{"); WriteNl (f);
WriteS (f, " pAttribute->Position = "); Prefix; WriteS (f, "Attribute.Position;"); WriteNl (f);
WriteS (f, " switch (Token) {"); WriteNl (f);
ForallClasses (Classes, ErrorActions);
WriteS (f, " }"); WriteNl (f);
WriteS (f, "}"); WriteNl (f);
WriteS (f, "%%"); WriteNl (f);
ForallClasses (Classes, ScanSpec);
;
RETURN;
END;
END;
IF (t^.Kind = Tree.Class) THEN
(* line 220 "" *)
WITH t^.Class DO
(* line 220 "" *)
IF {Terminal, Referenced} <= Properties THEN
WN (Code);
IF HasAttributes IN Properties THEN WriteS (f, " S ");
ELSE WriteS (f, " N ");
END;
IF (String IN Properties) AND NOT (HasSelector IN Properties) THEN
WriteS (f, "yy"); WN (Code);
ELSE
WI (Selector);
END;
WriteS (f, " "); WI (Name); WriteNl (f);
END;
;
RETURN;
END;
END;
END ScanSpec;
PROCEDURE ErrorActions (t: Tree.tTree);
VAR yyTempo: RECORD CASE : INTEGER OF
END; END;
BEGIN
IF t = Tree.NoTree THEN RETURN; END;
CASE t^.Kind OF
| Tree.Class:
(* line 238 "" *)
WITH t^.Class DO
(* line 238 "" *)
IF {Terminal, Referenced, HasAttributes} <= Properties THEN
WriteS (f, " case /* "); WE (Name); WriteS (f, " */ "); WN (Code); WriteS (f, ": "); WriteNl (f);
TheClass := t;
ForallAttributes (t, ErrorActions);
WriteS (f, " break;"); WriteNl (f);
END;
;
RETURN;
END;
| Tree.ActionPart:
(* line 246 "" *)
WITH t^.ActionPart DO
(* line 246 "" *)
ErrorActions (Actions);
;
RETURN;
END;
| Tree.Assign:
(* line 249 "" *)
WITH t^.Assign DO
(* line 249 "" *)
ErrorActions (Results); WriteS (f, "="); ErrorActions (Arguments); WriteS (f, ";"); WriteNl (f);
ErrorActions (Next);
;
RETURN;
END;
| Tree.Copy:
(* line 253 "" *)
WITH t^.Copy DO
(* line 253 "" *)
ErrorActions (Results); WriteS (f, " = "); ErrorActions (Arguments); WriteS (f, ";"); WriteNl (f);
ErrorActions (Next);
;
RETURN;
END;
| Tree.TargetCode:
(* line 257 "" *)
WITH t^.TargetCode DO
(* line 257 "" *)
ErrorActions (Code); WriteS (f, ";"); WriteNl (f);
ErrorActions (Next);
;
RETURN;
END;
| Tree.Order:
(* line 261 "" *)
WITH t^.Order DO
(* line 261 "" *)
ErrorActions (Next);
;
RETURN;
END;
| Tree.Check:
(* line 264 "" *)
WITH t^.Check DO
(* line 264 "" *)
IF Statement # NoTree THEN
IF Condition # NoTree THEN
WriteS (f, "if ("); ErrorActions (Condition); WriteS (f, ") ; else { "); ErrorActions (Statement); WriteS (f, "; }"); WriteNl (f);
ELSE
WriteS (f, "{ "); ErrorActions (Statement); WriteS (f, "; }"); WriteNl (f);
END;
ELSE
WriteS (f, "(void) ("); ErrorActions (Condition); WriteS (f, ");"); WriteNl (f);
END;
ErrorActions (Next);
;
RETURN;
END;
| Tree.Designator:
(* line 276 "" *)
WITH t^.Designator DO
(* line 276 "" *)
WI (Selector); WriteS (f, ":"); WI (Attribute);
ErrorActions (Next);
;
RETURN;
END;
| Tree.Ident:
(* line 280 "" *)
WITH t^.Ident DO
(* line 280 "" *)
TheAttr := IdentifyAttribute (TheClass, Attribute);
IF TheAttr # NoTree THEN
WriteS (f, "pAttribute->");
IF Attribute = iPosition THEN
ELSIF (String IN TheClass^.Class.Properties) AND NOT (HasSelector IN TheClass^.Class.Properties) THEN
WriteS (f, "yy"); WN (TheClass^.Class.Code); WriteS (f, ".");
ELSE
WI (TheClass^.Class.Selector); WriteS (f, ".");
END;
END;
WI (Attribute);
ErrorActions (Next);
;
RETURN;
END;
| Tree.Any:
(* line 294 "" *)
WITH t^.Any DO
(* line 294 "" *)
WriteString (f, Code);
ErrorActions (Next);
;
RETURN;
END;
| Tree.Anys:
(* line 298 "" *)
WITH t^.Anys DO
(* line 298 "" *)
ErrorActions (Layouts);
ErrorActions (Next);
;
RETURN;
END;
| Tree.LayoutAny:
(* line 302 "" *)
WITH t^.LayoutAny DO
(* line 302 "" *)
WriteString (f, Code);
ErrorActions (Next);
;
RETURN;
END;
ELSE END;
END ErrorActions;
PROCEDURE ScanVariant (t: Tree.tTree);
VAR yyTempo: RECORD CASE : INTEGER OF
END; END;
BEGIN
IF t = Tree.NoTree THEN RETURN; END;
IF (t^.Kind = Tree.Class) THEN
(* line 310 "" *)
WITH t^.Class DO
(* line 310 "" *)
IF {Terminal, Referenced, HasAttributes} <= Properties THEN
WriteS (f, "typedef struct { tPosition yyPos; ");
TheClass := t;
ForallAttributes (t, RecordField);
IF (String IN Properties) AND NOT (HasSelector IN Properties) THEN
WriteS (f, "} /* "); WE (Name); WriteS (f, " */ yy"); WN (Code); WriteS (f, ";"); WriteNl (f);
ELSE
WriteS (f, "} yy"); WI (Selector); WriteS (f, ";"); WriteNl (f);
END;
END;
;
RETURN;
END;
END;
END ScanVariant;
PROCEDURE ScanAttr (t: Tree.tTree);
VAR yyTempo: RECORD CASE : INTEGER OF
END; END;
BEGIN
IF t = Tree.NoTree THEN RETURN; END;
IF (t^.Kind = Tree.Class) THEN
(* line 326 "" *)
WITH t^.Class DO
(* line 326 "" *)
IF {Terminal, Referenced, HasAttributes} <= Properties THEN
IF (String IN Properties) AND NOT (HasSelector IN Properties) THEN
WriteS (f, " yy"); WN (Code); WriteS (f, " /* "); WE (Name); WriteS (f, " */ yy"); WN (Code); WriteS (f, ";"); WriteNl (f);
ELSE
WriteS (f, " yy"); WI (Selector); WriteS (f, " "); WI (Selector); WriteS (f, ";"); WriteNl (f);
END;
END;
;
RETURN;
END;
END;
END ScanAttr;
PROCEDURE ParsVariant (t: Tree.tTree);
VAR yyTempo: RECORD CASE : INTEGER OF
END; END;
BEGIN
IF t = Tree.NoTree THEN RETURN; END;
IF (t^.Kind = Tree.Class) THEN
(* line 339 "" *)
WITH t^.Class DO
(* line 339 "" *)
IF {Nonterminal, Referenced, HasAttributes} <= Properties THEN
WriteS (f, "typedef struct { ");
TheClass := t;
ForallAttributes (Attributes, RecordField);
GenExt (Extensions);
IF (String IN Properties) AND NOT (HasSelector IN Properties) THEN
WriteS (f, "} /* "); WE (Name); WriteS (f, " */ yy"); WN (Name); WriteS (f, ";"); WriteNl (f);
ELSE
WriteS (f, "} yy"); WI (Selector); WriteS (f, ";"); WriteNl (f);
END;
END;
ParsVariant (Next);
;
RETURN;
END;
END;
END ParsVariant;
PROCEDURE GenExt (t: Tree.tTree);
VAR yyTempo: RECORD CASE : INTEGER OF
END; END;
BEGIN
IF t = Tree.NoTree THEN RETURN; END;
IF (t^.Kind = Tree.Class) THEN
(* line 357 "" *)
WITH t^.Class DO
(* line 357 "" *)
ForallAttributes (Attributes, RecordField);
GenExt (Extensions);
GenExt (Next);
;
RETURN;
END;
END;
END GenExt;
PROCEDURE Token (t: Tree.tTree);
VAR yyTempo: RECORD CASE : INTEGER OF
END; END;
BEGIN
IF t = Tree.NoTree THEN RETURN; END;
IF (t^.Kind = Tree.Class) THEN
(* line 366 "" *)
WITH t^.Class DO
(* line 366 "" *)
IF {Terminal, Referenced} <= Properties THEN
WriteName (Name); WriteS (f, " = "); WN (Code); WriteNl (f);
END;
;
RETURN;
END;
END;
END Token;
PROCEDURE RecordField (t: Tree.tTree);
VAR yyTempo: RECORD CASE : INTEGER OF
END; END;
BEGIN
IF t = Tree.NoTree THEN RETURN; END;
IF (t^.Kind = Tree.Attribute) THEN
(* line 375 "" *)
WITH t^.Attribute DO
(* line 375 "" *)
IF (NoCodeAttr * Properties) = {} THEN
IF (Nonterminal IN TheClass^.Class.Properties) OR (Name # iPosition) THEN
WI (Type); WriteS (f, " "); WI (Name); WriteS (f, "; ");
END;
END;
;
RETURN;
END;
END;
END RecordField;
PROCEDURE PrecDefs (t: Tree.tTree);
VAR yyTempo: RECORD CASE : INTEGER OF
END; END;
BEGIN
IF t = Tree.NoTree THEN RETURN; END;
IF (t^.Kind = Tree.LeftAssoc) THEN
(* line 386 "" *)
WITH t^.LeftAssoc DO
(* line 386 "" *)
WriteS (f, "LEFT "); PrecDefs (Names); WriteNl (f);
PrecDefs (Next);
;
RETURN;
END;
END;
IF (t^.Kind = Tree.RightAssoc) THEN
(* line 390 "" *)
WITH t^.RightAssoc DO
(* line 390 "" *)
WriteS (f, "RIGHT"); PrecDefs (Names); WriteNl (f);
PrecDefs (Next);
;
RETURN;
END;
END;
IF (t^.Kind = Tree.NonAssoc) THEN
(* line 394 "" *)
WITH t^.NonAssoc DO
(* line 394 "" *)
WriteS (f, "NONE "); PrecDefs (Names); WriteNl (f);
PrecDefs (Next);
;
RETURN;
END;
END;
IF (t^.Kind = Tree.Name) THEN
(* line 398 "" *)
WITH t^.Name DO
(* line 398 "" *)
WriteS (f, " "); WI (Name);
PrecDefs (Next);
;
RETURN;
END;
END;
END PrecDefs;
PROCEDURE Grammar (t: Tree.tTree);
VAR yyTempo: RECORD CASE : INTEGER OF
END; END;
BEGIN
IF t = Tree.NoTree THEN RETURN; END;
IF (t^.Kind = Tree.Class) THEN
(* line 406 "" *)
WITH t^.Class DO
(* line 406 "" *)
IF Extensions^.Kind = Tree.NoClass THEN (* Low ? *)
WITH TheClass^.Class DO
IF String IN Properties THEN WriteS (f, "yy"); WN (Name); ELSE WriteName (Name); END;
END;
WriteS (f, " : ");
ActClass := t;
PrevActionIndex := 0;
IsImplicit := FALSE;
ForallAttributes (t, Rule);
IF Prec # NoIdent THEN WriteS (f, "PREC "); WI (Prec); WriteS (f, " "); END;
WriteS (f, "."); WriteNl (f);
PrevActionIndex := 0;
IsImplicit := TRUE;
ForallAttributes (t, Implicit);
ELSE
Rule (Extensions);
END;
;
RETURN;
END;
END;
END Grammar;
PROCEDURE Rule (t: Tree.tTree);
VAR yyTempo: RECORD CASE : INTEGER OF
END; END;
BEGIN
IF t = Tree.NoTree THEN RETURN; END;
CASE t^.Kind OF
| Tree.Class:
(* line 429 "" *)
WITH t^.Class DO
(* line 429 "" *)
Grammar (t);
Rule (Next);
;
RETURN;
END;
| Tree.Child:
(* line 433 "" *)
WITH t^.Child DO
(* line 433 "" *)
IF {String, Nonterminal} <= Class^.Class.Properties THEN WriteS (f, "yy"); WN (Type); ELSE WriteName (Type); END; WriteS (f, " ");
;
RETURN;
END;
| Tree.ActionPart:
(* line 436 "" *)
WITH t^.ActionPart DO
(* line 436 "" *)
IF IsLast (ActClass, t) THEN
WriteS (f, "{");
IF PrevActionIndex # 0 THEN
Node := GetBaseClass (TheClass);
WITH Node^.Class DO
IF HasAttributes IN Properties THEN
WriteS (f, " $$.");
IF String IN Properties THEN WriteS (f, "yy"); WN (Name); ELSE WI (Name); END;
WriteS (f, " = $"); WN (PrevActionIndex); WriteS (f, ".");
IF String IN Properties THEN WriteS (f, "yy"); WN (Name); ELSE WI (Name); END;
WriteS (f, ";"); WriteNl (f);
END;
END;
END;
Rule (Actions);
WriteS (f, "} ");
ELSE
WriteS (f, "xx"); WN (Name); WriteS (f, " ");
END;
PrevActionIndex := ParsIndex;
;
RETURN;
END;
| Tree.Assign:
(* line 458 "" *)
WITH t^.Assign DO
(* line 458 "" *)
Rule (Results); WriteS (f, "="); Rule (Arguments); WriteS (f, ";"); WriteNl (f);
Rule (Next);
;
RETURN;
END;
| Tree.Copy:
(* line 462 "" *)
WITH t^.Copy DO
(* line 462 "" *)
Rule (Results); WriteS (f, " = "); Rule (Arguments); WriteS (f, ";"); WriteNl (f);
Rule (Next);
;
RETURN;
END;
| Tree.TargetCode:
(* line 466 "" *)
WITH t^.TargetCode DO
(* line 466 "" *)
Rule (Code); WriteS (f, ";"); WriteNl (f);
Rule (Next);
;
RETURN;
END;
| Tree.Order:
(* line 470 "" *)
WITH t^.Order DO
(* line 470 "" *)
Rule (Next);
;
RETURN;
END;
| Tree.Check:
(* line 473 "" *)
WITH t^.Check DO
(* line 473 "" *)
IF Statement # NoTree THEN
IF Condition # NoTree THEN
WriteS (f, "if ("); Rule (Condition); WriteS (f, ") ; else { "); Rule (Statement); WriteS (f, "; }"); WriteNl (f);
ELSE
WriteS (f, "{ "); Rule (Statement); WriteS (f, "; }");
END;
ELSE
WriteS (f, "(void) ("); Rule (Condition); WriteS (f, ");"); WriteNl (f);
END;
Rule (Next);
;
RETURN;
END;
| Tree.Designator:
(* line 485 "" *)
WITH t^.Designator DO
(* line 485 "" *)
TheAttr := IdentifyAttribute (ActClass, Selector);
IF TheAttr # NoTree THEN
Node := TheAttr^.Child.Class;
IF Node # NoTree THEN
WriteS (f, "$");
IF NOT IsImplicit THEN
WN (TheAttr^.Child.ParsIndex);
ELSE
WN (SHORTINT (TheAttr^.Child.ParsIndex + 1 - ActActionIndex));
END;
IF Nonterminal IN Node^.Class.Properties THEN (* nonterminal *)
Node := GetBaseClass (Node);
IF (String IN Node^.Class.Properties) AND NOT (HasSelector IN Node^.Class.Properties) THEN
WriteS (f, ".yy"); WN (Node^.Class.Name);
ELSE
WriteS (f, "."); WI (Node^.Class.Name);
END;
ELSE (* terminal *)
WriteS (f, ".Scan");
IF Attribute = iPosition THEN
ELSIF (String IN Node^.Class.Properties) AND NOT (HasSelector IN Node^.Class.Properties) THEN
WriteS (f, ".yy"); WN (Node^.Class.Code);
ELSE
WriteS (f, "."); WI (Node^.Class.Selector);
END;
END;
WriteS (f, "."); WI (Attribute);
ELSE
WI (Selector); WriteS (f, ":"); WI (Attribute);
END;
ELSE
WI (Selector); WriteS (f, ":"); WI (Attribute);
END;
Rule (Next);
;
RETURN;
END;
| Tree.Ident:
(* line 521 "" *)
WITH t^.Ident DO
(* line 521 "" *)
TheAttr := IdentifyAttribute (ActClass, Attribute);
Node := GetBaseClass (TheClass);
IF TheAttr # NoTree THEN
IF (String IN Node^.Class.Properties) AND NOT (HasSelector IN Node^.Class.Properties) THEN
WriteS (f, "$$.yy"); WN (Node^.Class.Name); WriteS (f, "."); WI (Attribute);
ELSE
WriteS (f, "$$."); WI (Node^.Class.Name); WriteS (f, "."); WI (Attribute);
END;
ELSE
WI (Attribute);
END;
Rule (Next);
;
RETURN;
END;
| Tree.Any:
(* line 535 "" *)
WITH t^.Any DO
(* line 535 "" *)
WriteString (f, Code);
Rule (Next);
;
RETURN;
END;
| Tree.Anys:
(* line 539 "" *)
WITH t^.Anys DO
(* line 539 "" *)
Rule (Layouts);
Rule (Next);
;
RETURN;
END;
| Tree.LayoutAny:
(* line 543 "" *)
WITH t^.LayoutAny DO
(* line 543 "" *)
WriteString (f, Code);
Rule (Next);
;
RETURN;
END;
ELSE END;
END Rule;
PROCEDURE Implicit (t: Tree.tTree);
VAR yyTempo: RECORD CASE : INTEGER OF
END; END;
BEGIN
IF t = Tree.NoTree THEN RETURN; END;
IF (t^.Kind = Tree.ActionPart) THEN
(* line 551 "" *)
WITH t^.ActionPart DO
(* line 551 "" *)
IF NOT (Generated IN Properties) AND NOT IsLast (ActClass, t) THEN
INCL (Properties, Generated);
ActActionIndex := ParsIndex;
WriteS (f, "xx"); WN (Name); WriteS (f, " : {");
IF PrevActionIndex # 0 THEN
Node := GetBaseClass (TheClass);
WITH Node^.Class DO
IF HasAttributes IN Properties THEN
WriteS (f, " $$.");
IF String IN Properties THEN WriteS (f, "yy"); WN (Name); ELSE WI (Name); END;
WriteS (f, " = $"); WN (SHORTINT (PrevActionIndex + 1 - ActActionIndex)); WriteS (f, ".");
IF String IN Properties THEN WriteS (f, "yy"); WN (Name); ELSE WI (Name); END;
WriteS (f, ";"); WriteNl (f);
END;
END;
END;
Rule (Actions);
WriteS (f, "} ."); WriteNl (f);
END;
PrevActionIndex := ParsIndex;
;
RETURN;
END;
END;
END Implicit;
PROCEDURE WriteName (Name: tIdent);
VAR yyTempo: RECORD CASE : INTEGER OF
END; END;
BEGIN
IF (Name = (iOper)) THEN
(* line 576 "" *)
(* line 581 "" *)
WriteS (f, "\");
(* line 581 "" *)
WI (Name);
RETURN;
END;
IF (Name = (iLeft)) THEN
(* line 576 "" *)
(* line 581 "" *)
WriteS (f, "\");
(* line 581 "" *)
WI (Name);
RETURN;
END;
IF (Name = (iRight)) THEN
(* line 576 "" *)
(* line 581 "" *)
WriteS (f, "\");
(* line 581 "" *)
WI (Name);
RETURN;
END;
IF (Name = (iNone)) THEN
(* line 576 "" *)
(* line 581 "" *)
WriteS (f, "\");
(* line 581 "" *)
WI (Name);
RETURN;
END;
IF (Name = (iPrec)) THEN
(* line 576 "" *)
(* line 581 "" *)
WriteS (f, "\");
(* line 581 "" *)
WI (Name);
RETURN;
END;
IF (Name = (iRule)) THEN
(* line 576 "" *)
(* line 581 "" *)
WriteS (f, "\");
(* line 581 "" *)
WI (Name);
RETURN;
END;
(* line 582 "" *)
(* line 582 "" *)
WI (Name);
RETURN;
END WriteName;
PROCEDURE BeginGramC;
BEGIN
(* line 87 "" *)
ArrayToString ("OPER" , s); iOper := MakeIdent (s);
ArrayToString ("RIGHT" , s); iRight := MakeIdent (s);
ArrayToString ("LEFT" , s); iLeft := MakeIdent (s);
ArrayToString ("NONE" , s); iNone := MakeIdent (s);
ArrayToString ("PREC" , s); iPrec := MakeIdent (s);
ArrayToString ("RULE" , s); iRule := MakeIdent (s);
END BeginGramC;
PROCEDURE CloseGramC;
BEGIN
END CloseGramC;
PROCEDURE yyExit;
BEGIN
IO.CloseIO; System.Exit (1);
END yyExit;
BEGIN
yyf := IO.StdOutput;
Exit := yyExit;
BeginGramC;
END GramC.